#include<bits/stdc++.h>
using namespace std;
int d[100005],u[100005],a[100005],f[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n,m,l,v,sum=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&u[i],&a[i]);
        }
        int Max=0,sum=0;
        for(int i=1;i<=w;i++){
            scanf("%d",&f[i]);
            Max=max(Max,f[i]);
        }
        for(int i=1;i<=n;i++){
            if(u[i]>=v&&d[i]<Max){
                sum++;
            }
        }
        cout<<sum<<" "<<m-1<<endl;
    }
    return 0;
}
